﻿Imports System.IO

Public Class EODControl
    Dim MyLib As New Class1
    Private Sub EODControl_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CheckForIllegalCrossThreadCalls = False
        MyLib.LoadStores(DataGridView1)

    End Sub

    Private Sub EditToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EditToolStripMenuItem.Click
        Dim t As New Threading.Thread(AddressOf EditEcomhook)
        t.Start()

    End Sub

    Sub EditEcomhook()
        Try
            For Each selecteditems As DataGridViewRow In DataGridView1.SelectedRows

                Dim ecomloc As String
                ecomloc = "\\" & selecteditems.Cells(4).Value & "\BOOTDRV\" & selecteditems.Cells(3).Value
                appentlogs(selecteditems.Cells(1).Value & " " & selecteditems.Cells(2).Value & " Looking for ecomhook...")
                Dim EcomFullname As String
                EcomFullname = ecomloc & My.Resources.Ecomhook

                Dim ecomhook As New FileInfo(EcomFullname)

                Dim ecomhookstream As StreamReader
                ecomhookstream = ecomhook.OpenText
                appentlogs(selecteditems.Cells(1).Value & " " & selecteditems.Cells(2).Value & " Opening ecomhook...")
                Dim ecomhooktext As String = ecomhookstream.ReadToEnd
                appentlogs(selecteditems.Cells(1).Value & " " & selecteditems.Cells(2).Value & " Reading ecomhook...")
                Dim Dialog As New ecomhookdialog
                Dialog.TextBox1.Text = ecomhooktext
                Dialog.ShowDialog()

                If Dialog.DialogResult = DialogResult.OK Then
                    Dim NewHook As String
                    NewHook = Dialog.TextBox1.Text
                    ecomhookstream.Close()
                    Using writer As StreamWriter = New StreamWriter(ecomhook.FullName)
                        appentlogs(selecteditems.Cells(1).Value & " " & selecteditems.Cells(2).Value & " Writing Changes ecomhook...")
                        writer.WriteLine(NewHook)
                        appentlogs(selecteditems.Cells(1).Value & " " & selecteditems.Cells(2).Value & " Writing Changes Done.")
                    End Using
                End If
            Next
            appentlogs("Done")
        Catch ex As Exception
            appentlogs(ex.Message)
        End Try
    End Sub
    Sub appentlogs(Message As String)
        txtlogs.Text = Now.ToString & ": " & Message & txtlogs.Text & vbCrLf
        ' txtlogs.AppendText(Now.ToString & ": " & Message & vbCrLf)
    End Sub
End Class
